/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: jse2204 - Arr10
 * <p>Powered by webrx On 2022-09-07 09:08:46
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Arr10 {
    public static void main(String[] args) {
        Integer[] nums = {1, 2, 3, 4, 5, 6, 7, 8};
        System.out.println(Arrays.toString(nums));

        //使用Arrays工具类的sort排序方法，
        Arrays.sort(nums, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(nums, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(nums, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(nums, (a, b) -> Math.random() > .5 ? 1 : -1);
        System.out.println(Arrays.toString(nums));


        //洗牌
        Random rand = new Random();
        int i = 0;
        while (true) {
            //0 - nums.length(不包括.length)
            int a = rand.nextInt(nums.length);
            int b = rand.nextInt(nums.length);
            if (a == b) continue;
            int t = nums[a];
            nums[a] = nums[b];
            nums[b] = t;
            ++i;
            if (i >= rand.nextInt(nums.length, nums.length * 2)) {
                break;
            }
        }

        //洗牌输出
        System.out.println(Arrays.toString(nums));

    }
}
